from odoo import api, models, fields, _
from odoo.exceptions import ValidationError


class ShipInstructions(models.Model):
    _inherit = 'ship.instructions'

    def confirm_shipment(self, admin=False):
        for rec in self.sale_ids:
            if rec.s_disable_delivery:
                # 当前订单已经锁定，不允许出货
                raise ValidationError(_('The current order has been locked and cannot be shipped 【{}】'.format(rec.name)))
            # 锁厂编
            if rec.product_id.s_disable_delivery:
                raise ValidationError(_('Product Code:【{}】,  Shipping has been prohibited'.format(rec.product_id.name)))
        return super().confirm_shipment(admin=admin)
